// pages/personal-address/personal-address.js
import get from '../../util/get'
import post from '../../util/post'
Page({

    /**
     * 页面的初始数据
     */
    data: {
      address:[]
    },
    back(){
        wx.navigateBack()
    },
    gotoModify(e){
      let i =  e.currentTarget.id - 1
      let id = e.currentTarget.id
      let consignee = this.data.address[i].receiver
      let phone = this.data.address[i].phone
      let address = this.data.address[i].city
      let detailedaddress = this.data.address[i].area
        wx.navigateTo({
          url: `/pages/address-modify/address-modify?consignee=${consignee}&phone=${phone}&address=${address}&detailedaddress=${detailedaddress}&id=${id}`,
        })
    },
    gotoappend(){
        wx.navigateTo({
          url: '/pages/address-append/address-append',
        })
    },
    async showaddress(){
      let id = getApp().globalData.id
      let address = await get(`wx/address?id=${1}`)
      console.log(address)
      this.setData({
        address:address
      })
      console.log(this.data.address)
    },
    async delete(e){
      let id = e.currentTarget.id
      await post('wx/addressdelete',{id:id}).then(res=>{
        console.log(res)
      })
      this.onLoad()
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.showaddress()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
  
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})